package com.jlpay.openapi.demo.trans.b2c;

import com.jlpay.open.jlpay.sdk.java.model.trans.b2c.request.MicroPayPreAuthRequest;
import com.jlpay.open.jlpay.sdk.java.model.trans.b2c.response.MicroPayPreAuthResponse;
import com.jlpay.open.jlpay.sdk.java.utils.json.JsonUtils;
import com.jlpay.openapi.demo.JlpayOpenApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author dengwenning
 * @since 2024/9/23
 **/
public class MicroPayPreAuthService {
    private static final Logger LOGGER = LoggerFactory.getLogger(MicroPayPreAuthService.class);

    public static void main(String[] args) {
        MicroPayPreAuthRequest microPayPreAuthRequest = buildMicroPayPreAuthRequest();
        MicroPayPreAuthResponse microPayPreAuthResponse = JlpayOpenApiService.openMerchService()
                .post(microPayPreAuthRequest, MicroPayPreAuthResponse.class);
        LOGGER.info("付款码支付(B2C)付款码预授权响应:{}", JsonUtils.toString(microPayPreAuthResponse));
    }

    private static MicroPayPreAuthRequest buildMicroPayPreAuthRequest() {
        MicroPayPreAuthRequest microPayPreAuthRequest = new MicroPayPreAuthRequest();

        microPayPreAuthRequest.setMchId("849584358120018");
        microPayPreAuthRequest.setTermNo("60131234");
        microPayPreAuthRequest.setPayType("wxpay");
        microPayPreAuthRequest.setOutTradeNo("ld201911023465529");
        microPayPreAuthRequest.setPaymentValidTime("10");
        microPayPreAuthRequest.setGuaranteeExpiry("30");
        microPayPreAuthRequest.setBody("充值中心-会员充值");
        microPayPreAuthRequest.setAttach("商城—-易拉宝10个打印纸20箱");
        microPayPreAuthRequest.setTotalFee("1");
        microPayPreAuthRequest.setAuthCode("131208648101095993");
        microPayPreAuthRequest.setRemark("该订单物流请走顺丰快递");
        microPayPreAuthRequest.setOpUserId("001");
        microPayPreAuthRequest.setOpShopId("GD_SZ_001");
        microPayPreAuthRequest.setDeviceInfo("N50007A8890");
        microPayPreAuthRequest.setMchCreateIp("123.12.12.123");
        microPayPreAuthRequest.setTransAddress("深圳市南山区科技二路10号");
        microPayPreAuthRequest.setAreaCode("4403");
        microPayPreAuthRequest.setLongitude("116.078631");
        microPayPreAuthRequest.setLatitude("39.71274");
        microPayPreAuthRequest.setSyncAble(false);
        microPayPreAuthRequest.setSubAppid("wxid_129752pfasf1671");

        return microPayPreAuthRequest;
    }
}
